#!/bin/bash
echo "========1. Dropping previous database..."
/usr/lib/postgresql/8.3/bin/dropdb -h localhost -p 5132 tpch

echo "========2. Creating new database..."
/usr/lib/postgresql/8.3/bin/createdb -h localhost -p 5132 tpch

echo "========3. Importing table structure..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch < /local/group3705/dbgen/dss.ddl

echo "========4. Creating the user and granting..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch < /local/group3705/server/create_grant.sql

echo "========5. Generating the database..."
cd /local/group3705/dbgen
./dbgen -f -v -s 0.1

echo "========6. Removing trailing | chars..."
/local/group3705/server/remove_trailing.sh

echo "========7. Importing generated database..."
/usr/lib/postgresql/8.3/bin/psql -h localhost -p 5132 tpch < /local/group3705/server/table_copy.sql
